7873bd
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.collections.keyvalue;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.util.Arrays;
 
@@ -54,7 +56,7 @@
public class MultiKey implements Serializable {
     /** The individual keys */
     private final Object[] keys;
     /** The cached hashCode */
-    private final int hashCode;
+    private transient int hashCode;
     
     /**
      * Constructor taking two keys.
@@ -164,13 +166,7 @@
public class MultiKey implements Serializable {
             this.keys = keys;
         }
         
-        int total = 0;
-        for (int i = 0; i < keys.length; i++) {
-            if (keys[i] != null) {
-                total ^= keys[i].hashCode();
-            }
-        }
-        hashCode = total;
+        calculateHashCode(keys);
     }
     
     //-----------------------------------------------------------------------
@@ -255,4 +251,29 @@
public class MultiKey implements Serializable {
         return "MultiKey" + Arrays.asList(keys).toString();
     }
 
+	/**
+	 * Calculate the hash code of the instance using the provided keys.
+	 * @param keys
+	 */
+	private void calculateHashCode(Object[] keys)
+	{
+		int total = 0;
+        for (int i = 0; i < keys.length; i++) {
+            if (keys[i] != null) {
+                total ^= keys[i].hashCode();
+            }
+        }
+        hashCode = total;
+	}
+	
+	/**
+	 * Recalculate the hash code after deserialization. The hash code of some
+	 * keys might have change (hash codes based on the system hash code are
+	 * only stable for the same process). 
+	 * @return the instance with recalculated hash code
+	 */
+	private Object readResolve() {
+		calculateHashCode(keys);
+		return this;
+	}
 }
